#include "Thread.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cassert>

namespace gti
{

Thread::Thread()
{
	memset((void*)&thread_info,0,sizeof(pthread_t));
	state = STOPPED;
}

void Thread::execute( function_callback f, void* idata )
{
	state = RUNNING;

	data.data = idata;
	data.thread = this;

	pthread_mutex_init(&global_mutex, NULL);
	pthread_create(&thread_info, NULL, f, (void *)&data);
	//state = FINNISHED;
}

void Thread::lock()
{
	int ret = pthread_mutex_lock (&global_mutex);
	assert(ret==0);
}

void Thread::unlock()
{
	int ret = pthread_mutex_unlock (&global_mutex);
	assert(ret==0);
}

void Thread::kill()
{
	//TODO
}

/*void Thread::keepThreads()
{
	pthread_exit(NULL);
}*/

}
